/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-var-requires */
/*
 * @Author: songdengwei
 * @Date: 2021-08-04 17:54:14
 * @LastEditors: songdengwei
 * @LastEditTime: 2020-07-21
 * @Description:
 */
import CryptoJS from "crypto-js";

const key = CryptoJS.enc.Utf8.parse("f5798748cda74f4a5067ae49624270a8"); //十六位十六进制数作为密钥
const iv = CryptoJS.enc.Utf8.parse("");

//解密方法
export const decryptFn = (word:string):string => {
  const encryptedHexStr = CryptoJS.enc.Hex.parse(word);
  const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
  const decrypt = CryptoJS.AES.decrypt(srcs, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr.toString();
};

//加密方法
export const encryptFn = (word:string):string => {
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const encrypted = CryptoJS.AES.encrypt(srcs, key, {
    iv: iv,
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7,
  });
  return encrypted.ciphertext.toString().toUpperCase();
};
